//
//  TokenManager.m
//  RYMart
//
//  Created by iMac on 2017/11/2.
//  Copyright © 2017年 Jason. All rights reserved.
//

#import "TokenManager.h"

static NSString *const Ry_Token = @"token";
static NSString *const User_id = @"user_id";



static NSString *const SectionMain = @"section_main"; //1为归属部门  2为集团归属部门
static NSString *const SectionNormal = @"section_normal"; //1为部门负责人
static NSString *const LeaderMain = @"leader_main"; //1为领导负责人
static NSString *const LeaderNormal = @"leader_normal"; //1为领导查看权限
static NSString *const IsheadOffice = @"is_headOffice"; //1为领导查看权限
static NSString *const GgetHotTel = @"get_hotTel";
@implementation TokenManager

+ (void)saveToken:(NSString *)token {
    if (token.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:token forKey:Ry_Token];
}

+ (NSString *)getToken {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *token = [singleUserDefault valueForKey:Ry_Token];
    return token.length > 0?token:@"";
}

+ (void)removeToken {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault removeObjectForKey:Ry_Token];
}

+ (BOOL)loginStatus {
    if ([TokenManager getToken].length == 0) {
        [[ToastManager shardInstance] showToast:@"请先登录"];
        return NO;
    }
    return YES;
}

+ (void)saveUserId:(NSString *)userId {
    if (userId.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:userId forKey:User_id];
}

+ (NSString *)getUserId {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *userId = [singleUserDefault valueForKey:User_id];
    return userId.length > 0?userId:@"";
}

+ (void)removeUserId {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault removeObjectForKey:User_id];
}



+ (void)saveSection_main:(NSString *)section_main {
    if (section_main.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:section_main forKey:SectionMain];
}

+ (NSString *)getSection_main {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *userId = [singleUserDefault valueForKey:SectionMain];
    return userId.length > 0?userId:@"";
}

//+ (void)removeUserId {
//    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
//    [singleUserDefault removeObjectForKey:User_id];
//}

+ (void)saveSection_normal:(NSString *)section_normal {
    if (section_normal.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:section_normal forKey:SectionNormal];
}

+ (NSString *)getSection_normal {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *userId = [singleUserDefault valueForKey:SectionNormal];
    return userId.length > 0?userId:@"";
}

+ (void)saveLeader_main:(NSString *)leader_main {
    if (leader_main.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:leader_main forKey:LeaderMain];
}

+ (NSString *)getLeader_main {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *userId = [singleUserDefault valueForKey:LeaderMain];
    return userId.length > 0?userId:@"";
}

+ (void)saveLeader_normal:(NSString *)leader_normal{
    if (leader_normal.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:leader_normal forKey:LeaderNormal];
}

+ (NSString *)getLeader_normal {
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *userId = [singleUserDefault valueForKey:LeaderNormal];
    return userId.length > 0?userId:@"";
}

+ (void)saveIsheadOffice:(NSString *)is_headOffice{
    
    if (is_headOffice.length == 0) return;
      NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
      [singleUserDefault setValue:is_headOffice forKey:IsheadOffice];
    
}
+ (NSString *)getIsheadOffice{
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
    NSString *userId = [singleUserDefault valueForKey:IsheadOffice];
    return userId.length > 0?userId:@"";
    
}

+ (void)saveGetHotTel:(NSString *)hotTel{
    if (hotTel.length == 0) return;
    NSUserDefaults *singleUserDefault = [NSUserDefaults standardUserDefaults];
    [singleUserDefault setValue:hotTel forKey:GgetHotTel];
}
+ (NSString *)getHotTel{
    NSUserDefaults* singleUserDefault = [NSUserDefaults standardUserDefaults];
       NSString *userId = [singleUserDefault valueForKey:GgetHotTel];
       return userId.length > 0?userId:@"";
    
}

@end
